<?php

namespace App\Console\Commands;

use Carbon\Carbon;
use App\Models\User;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;

class UsersCount extends Command
{
	protected $signature = 'cc:users-count';

	protected $description = "Users increasing statistic";

	public function __construct()
	{
		parent::__construct();
	}

	public function handle()
	{

		User::query()->chunk(50, function (Collection $users) {

            if ($users->isEmpty()) return false;

            /**
             * @var User $user
             */
            foreach ($users as $user) {

                $user->cleanStormUnpaidCache();
                $user->cleanStormPendingCache();
                $user->cleanStormRunningCache();
                $user->cleanStormFinishedCache();

                $user->update([
                    'is_gold_intern' => false,
                    'is_gold_master' => false,
                    'gold_coins' => 10000,
                    'gold_beans' => 10000,
                    'gold_cashes' => 10000,
                    'gold_subsidies' => 10000,
                    'has_given_parent_cash' => false,
                    'last_team_prize_user_id' => 0,
                    'pre_free_withdraw_quota' => 0,
                    'gold_wastes_order_at' => null,
                    'gold_wastes_subsidy_at' => null,
                    'dividend_all' => 0,
                    'dividend_day' => 0,
                    'resold_profit' => 0,
                    'dividend_parent_reward' => 0
                ]);
            }

            return true;

        });

		

		Log::info("{$date->toDateString()} - {$count}人");

		usleep(10);
	
	}
}
